<?php
namespace app\Admin\controller;
use app\Admin\model\Note as NoteModel;
use app\admin\controller\Base;

class Note extends Base
{
    public function index()
    {

    	$list=db('note')->field('n.*,c.catename,u.phone')->alias('n')->join('f_cate c','n.cateid=c.id')->join('f_user u','n.uid=u.id')->order('n.id')->paginate(5);

        $this->assign('list',$list);
        return view();
    }

    public function see()
    {
        $id=input('id');
        $list=db('note')->find($id);
        $uid = $list['uid'];
        $user=db('information')->find($uid);
        $list['username'] = $user['name'];
        $this->assign('list',$list);
        return view();
    }

    public function edit(){
    	$id = input('id');
        $note = db('note')->find($id);
        if ($note['status'] == 1) {
            $data = [
                'id' => $id,
                'status' => 0,
            ];
            db('note')->update($data);
            $this->redirect('index');
        } else {
            $data = [
                'id' => $id,
                'status' => 1,
            ];
            db('note')->update($data);
            $this->redirect('index');
        }
    }

    public function del(){
    	$id=input('id');
		if(db('note')->delete(input('id'))){
			$this->success('删除帖子成功！','index');
		}else{
			$this->error('删除帖子失败！');
		}
    	
    }



}
